import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.text.DateFormat;
import java.text.SimpleDateFormat;


public class JDBCLogTest {

	public static void main(String[] args) {
		// Specify the log file
		String strFileName = "mylog.log";
		File logFile = new File(strFileName);
		
		// Create the PrintWriter
		PrintWriter logWriter = null;
		boolean isAppend = true;
		
		try
		{
			logWriter = new PrintWriter(new FileOutputStream(logFile, isAppend));
		}
		catch (IOException e)
		{
			System.err.println("Error! " + e.getMessage());
			e.printStackTrace(System.err);
		}
		
		// Specify the logWriter for DriverManager
		DriverManager.setLogWriter(logWriter);
		
		// Write some log as examples
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
		java.util.Date date = new java.util.Date();
		
		date.setTime(System.currentTimeMillis());
		DriverManager.println("Log[" + dateFormat.format(date) + "]: This is the first sample log!");
		date.setTime(System.currentTimeMillis());
		DriverManager.println("Log[" + dateFormat.format(date) + "]: This is the second sample log!");

		// Release all resources
		logFile = null;
		logWriter.close();
		logWriter = null;
	}

}
